var http=require("http");
var fs=require("fs");

var path=require("path");

var url=require("url");

var querystring=require("querystring");


var server=http.createServer(function (req,res) {});

server.listen(2000);

server.on("request",function (req,res) {
    res.writeHead(200,"OK",{
        "content-type":"text/html;charset=utf-8"
    });
    var urlObj=url.parse(req.url);
    if(urlObj.path!="/favicon.ico"){
        if(urlObj.pathname=="/loginServer"){
            //get 提交
          /*  if(req.method.toLocaleUpperCase()=="GET"){
                var submitParameters=querystring.parse(urlObj.query);
                if(submitParameters.userName=="zyc"&&submitParameters.password=="123456"){
                    fs.readFile("./html/index.html",function (err,data) {
                        res.write(data.toString());
                        res.end();
                    });

                }
            }*/

          if(req.method.toLocaleUpperCase()=="POST"){
              var data="";
            req.on("data",function (chunk) {
                 data+=chunk;
            });
            req.on("end",function () {
                var cObj=querystring.parse(data);
                if(cObj.userName=="zyc"&&cObj.password=="123456"){
                    fs.readFile("./html/index.html",function (err,data) {
                        res.write(data.toString());
                        res.end();
                    });

                }
            })
          }

        }else if(urlObj.pathname=="/login"){
             fs.readFile("./html/login.html",function (err,data) {
                 res.write(data.toString());
                 res.end();
             })
        }
    }


});



